<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/6/21 0021
 * Time: 20:42
 */
if ($_SERVER["REQUEST_METHOD"] == "GET") {
    return;
}
$pid = $_REQUEST["pid"];
$pname = $_REQUEST["pname"];
$pprice = $_REQUEST["pprice"];
$imgUrlx = $_REQUEST["imgUrlx"];
$type = $_REQUEST["type"];
$p_number = $_REQUEST["p_number"];
$total = $p_number * $pprice;
$u_id = $_REQUEST["u_id"];

include "./DBheuper.php";

//准备sql语句
$query = "SELECT * FROM `cartslist` WHERE `p_id`='" . $pid . "' AND `p_name`='" . $pname . "' AND `p_type`='" . $type . "' AND `uid`='" . $u_id . "'";
print_r($query);
$result = sqlQuery($query);
if ($result->num_rows == 1) {
    $update = "UPDATE `cartslist` SET `p_number`=p_number+'".$p_number."',`p_total`=p_number*p_price WHERE `p_id`='".$pid."' AND `p_name`='".$pname."' AND `p_type`='".$type."' AND `uid`='".$u_id."'";
    $uResult = sqlQuery($update);
    if ($uResult >= 1) {
        print_r(json_encode(array("msg" => "加入成功u", "status" => 1)));
    } else {
        print_r(json_encode(array("msg" => "加入失败u", "status" => 2)));
    }
} else {
    $insert = "INSERT INTO `cartslist` (`p_id`,`p_name`,`p_price`,`p_url`,`p_type`,`p_number`,`p_total`,`uid`)";
    $insert .="VALUES ('" . $pid . "','" . $pname . "','" . $pprice . "','".$imgUrlx. "','" . $type . "','" . $p_number . "','" . $total . "','" . $u_id . "')";
    $uResult = sqlQuery($insert);
    if ($uResult == 1) {
        print_r(json_encode(array("msg" => "加入成功i", "status" => 1)));
    } else {
        print_r(json_encode(array("msg" => "加入失败i", "status" => 2)));
    }

}
